<%@ include file="../import_page.jsp"%>
<%@ page import="org.json.*"%>
<%
	//login checking
	if(!loginedChecking(session, UsersType.admin)) {
		//user don't login
		//redirect to home page
		response.sendRedirect(URL_HOMEPAGE);
		return;
	}
	
	String type = request.getParameter(PAR_USER_TYPE);
	UsersType usertype = null;
	try {
		usertype = UsersType.fromString(type);
	} catch (Exception err) {
		response.sendRedirect(URL_HOMEPAGE);
		return;
	}
	
	String names = request.getParameter(PAR_NAMES_LIST);
	//It shoudle not any space in the post back
	if(names == null)
		names = "";
	else if(names.indexOf(" ") > 0) {
		response.sendRedirect(URL_HOMEPAGE);
		return;
	}
	String[] nameArr = names.split("\\|");
	UserControl uCon = new UserControl();
	ArrayList<Users> listUser = uCon.searchUser(usertype, nameArr);
	
	JSONArray jArr = new JSONArray();
	Iterator<Users> luI = listUser.iterator();
	while(luI.hasNext()) {
		Users aUser = luI.next();
		JSONObject jObj = new JSONObject();
		jObj.put("id", aUser.getId());
		jObj.put("name", aUser.getName());
		jArr.put(jObj);
	}
	
	//response setting
	response.setContentType("text/json");
%>
<%= jArr.toString()%>